package com.jwx.mycar.service.impl;

import com.jwx.mycar.entity.dto.DraftDto;
import com.jwx.mycar.entity.po.Draft;
import com.jwx.mycar.entity.vo.ResultVo;
import com.jwx.mycar.mapper.DraftMapper;
import com.jwx.mycar.mapper.LableMapper;
import com.jwx.mycar.mapper.LableRelationMapper;
import com.jwx.mycar.mapper.StatMapper;
import com.jwx.mycar.service.DraftService;
import com.jwx.mycar.utils.ResultVOUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @ClassName DraftServiceImpl
 * @Description TODO
 * @Author jwx
 * @Date 2019/11/22 16:56
 * @Version 1.0
 **/
@Service
public class DraftServiceImpl implements DraftService {
    @Autowired
    DraftMapper draftMapper;
    @Autowired
    LableMapper lableMpper;
    @Autowired
    LableRelationMapper lableRelationMapper;
    @Autowired
    ResultVOUtil resultVOUtil;
    @Autowired
    StatMapper statMapper;
    @Override
    public ResultVo addDraft(DraftDto draftDto, List<Integer> labelsId) {
        try {
            boolean result1= draftMapper.insertDraft(draftDto);
            boolean result2=draftMapper.insertRelation(draftDto.getDraftId(),labelsId);
//            System.out.println(draftDto.getPicId());
//            int up =  statMapper.getAllUpCount("1575612143078966922");
//            System.out.println(up);
            if(result1&&result2)
            {
                return resultVOUtil.success(draftDto);
            }
            else{
                return resultVOUtil.fail();
            }
        }catch(Exception e){
            e.printStackTrace();
            return resultVOUtil.unkonwError();
        }
    }

    @Override
    public Draft getDraftById(String draftId) {
       return draftMapper.getById(draftId);
    }

    @Override
    public List<Draft> getAll() {
        return draftMapper.getAll();
    }

    @Override
    public List<Draft> getAllByUserId(String userId) {
        return draftMapper.getAllByUserId(userId);
    }

    @Override
    public List<Integer> getLabels(String draftId) {
        return lableRelationMapper.getLabels(draftId);
    }
}
